import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button } from 'antd';
import styles from './../Users.css';
import Factory from '../../factory';
import * as datetime from '../../../utils/datetime'
import dataTableCreate from '../../addons/DataTable'
const daoName = "IndiAccoDiviSq";
const renderReplace = (data) => {
    let value = ''
    if (data !== "1900-01-01T00:00:00Z") {
        value = data.replace("T", " ").replace("Z", "")
    }
    return value
};
const columns = [
    { title: '开户网点', dataIndex: 'KHWD', key: 'KHWD', width: 140, dispaly: true },
    { title: '开户日期', width: 110, sorter: true, key: 'KHR', caption: "KHR", render: data => datetime.format(data.KHR, "yyyy-MM-dd"), dispaly: true },
    // { title: '账号', dataIndex: 'ZH', key: 'ZH', width: 150, dispaly: true },
    // { title: '卡号', dataIndex: 'KH', key: 'KH', width: 150, dispaly: true },
    { title: '客户名称', dataIndex: 'KHMC', key: 'KHMC', width: 140, dispaly: true },
    { title: '证件号码', dataIndex: 'ZJHM', key: 'ZJHM', width: 180, dispaly: true },
    { title: '申请时间', width: 180, sorter: true, key: 'TJRQ', caption: "TJRQ", render: data => renderReplace(data.TJRQ), dispaly: true },
    { title: '审批时间', width: 180, sorter: true, key: 'SPSJ', caption: "SPSJ", render: data => renderReplace(data.SPSJ), dispaly: true },
    { title: '客户经理', width: 120, key: 'EMID', caption: "User.Name", render: data => data.User.Name, dispaly: true },
    { title: '分成比例', width: 80, dataIndex: 'DSVL', key: 'DSVL', dispaly: true },
    { title: '当前状态', width: 100, key: 'ISTY', dataIndex: 'ISTYCaption', dispaly: true },
    { title: '原因', width: 250, dataIndex: 'YY', key: 'YY', dispaly: true },
];
const controls = [
    { name: 'KHWD', required: true, type: 'text', label: '开户网点', grid: 12 / 24 },
    { name: 'KHR', required: true, type: 'date', label: '开户日期', grid: 12 / 24 },
    // { name: 'ZH', required: true, type: 'text', label: '账号', grid: 12 / 24 },
    // { name: 'KH', required: true, type: 'text', label: '卡号', grid: 12 / 24 },
    { name: 'KHMC', required: true, type: 'text', label: '客户名称', grid: 12 / 24 },
    { name: 'ZJHM', required: true, type: 'text', label: '证件号码', grid: 12 / 24 },
    { name: 'TJRQ', required: true, type: 'date', label: '申请时间', grid: 12 / 24 },
    { name: 'SPSJ', required: true, type: 'date', label: '审批时间', grid: 12 / 24 },
    { name: 'YY', required: true, type: 'text', label: '原因', grid: 12 / 24 },
];
const DataTable = dataTableCreate(daoName);
class GrckrdspqkForm extends Component {
    constructor(props) {
        super(props);
        this.state = {
            dataChange: false
        };
    }
    componentDidMount() {
        this.props.dispatch({
            type: `${daoName}/setKeyName`,
            payload: { keyName: "ID", permID: this.props.permID }
        });
        let sort = {
            field: 'TJRQ',
            order: 'descend'
        }
        let { userID } = this.props
        let whereItems = [];
        let WhereCauses = [];
        whereItems.push({
                FieldName: "SQRID",
                Operator: "=",
                FieldValues: '' + userID
            })
        WhereCauses.push({
            WhereItems: whereItems,
            RelationSign: "AND"
        })
        let seeks = WhereCauses;
        this.props.dispatch({
            type: `${daoName}/fetch`,
            payload: { daoName, page: 1, pageSize: 6, sorter: sort,seeks:seeks}
        });
        this.loadOptionData();
    }
    loadOptionData() {
        let options = []
        controls.map(c => {
            if (c.fetch) {
                let f = c.fetch;
                if (c.type === 'cascader-select') {
                    f.isCascader = true;
                }
                if (c.type !== 'search') {
                    options.push(f);
                }
            }
        })
        if (daoName && options.length > 0) {
            this.props.dispatch({ type: `${daoName}/fetchOptions`, payload: { options } });
        }
    }
    render() {
        let { permID,offsetHeight } = this.props
        return (
            <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
                <div className={styles.create}>
                </div>
                <div>
                    <DataTable ref="userTable" daoName={daoName} columns={columns} controls={controls} permID={permID} footerPageDisabled={true}/>
                </div>
            </div>
        )
    }
}
function mapStateToProps(state) {
    const { showEdit, record, selectedRowKeys, keyName } = state[daoName];
    const { userID, orgID, pOrgID, popedomTypes,offsetHeight } = state.menus;
    return {
        userID,
        orgID,
        pOrgID,
        popedomTypes,
        showEdit,
        selectedRowKeys,
        keyName,
        record,
        offsetHeight
    }
}
GrckrdspqkForm = connect(mapStateToProps)(GrckrdspqkForm)
export default GrckrdspqkForm;
let render = (props) => React.createElement(GrckrdspqkForm, props);

let f = new Factory()
f.set("GrckrdspqkForm", render)


